<!-- 对话框 ===================================== -->
<div class="modal small hide fade" id="gaollg-dialg">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">×</button>
		<h3 id="myModalLabel" data-d-who="title"></h3>
	</div>
	<div class="modal-body" data-d-who="body">
	</div>
	<div class="modal-footer" data-d-who="footer">
	</div>
</div>

<script>

	(function($){
		$.g = $.extend({}, $.g);
		var tmpl = $('#gaollg-dialg');
		tmpl.removeAttr('id');
		var body = $('body');
		$.g.dialg = function(option, init, callback){
			var o = $.extend({
					title : "对话框",
					content : "",
					button : '<button class="btn" data-dismiss="modal">取消</button>' + 
						'<button class="btn btn-danger" data-who="ok">确定</button>',
				}, option);
			/*
			var toJquey = function(o, attr){
				if((typeof o[attr]) == "string"){
					console.log(attr);
					console.log($("<div>" + o[attr] + "</div>").children());
					o[attr] = $("<div>" + o[attr] + "</div>").children();
				}
			};
			*/
			//toJquey(o, 'title');
			//toJquey(o, 'content');
			//toJquey(o, 'button');
			
			var d = tmpl.clone().appendTo(body);
			d.find('[data-d-who=title]').append(o.title);
			d.find('[data-d-who=body]').append(o.content);
			d.find('[data-d-who=footer]').append(o.button);
			d.modal({
			    backdrop:true,
			    keyboard:true,
			    show:true
			});
			
			d.option = o;
			
			//初始化
			if(callback){
				init(d);
			}else{
				callback = init;
			}
			
			d.close = function(){
				d.modal('hide');
			};
			d.find('[data-who]').on('click', function(){
				var v = $(this).attr('data-who');
				if(callback){
					callback(v, d);
				}
			});
			d.on('hidden', function () {
				d.remove();
			});
		}
	})(jQuery);

</script>